package com.scut.campus.controller;

import com.scut.campus.constant.JwtClaimsConstant;
import com.scut.campus.dto.UserLoginDTO;
import com.scut.campus.entity.User;
import com.scut.campus.properties.JwtProperties;
import com.scut.campus.response.Result;
import com.scut.campus.service.UserService;
import com.scut.campus.utils.JwtUtil;
import com.scut.campus.vo.UserLoginVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;



@RestController
@RequestMapping("/user")
@Tag(name = "微信登录接口")
@Slf4j
public class WxLoginController {
    @Autowired
    private UserService userService;
    @Autowired
    private JwtProperties jwtProperties;

    @PostMapping("/user/login")
    @Operation(summary = "微信登录")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO){
        //User user=userService.wxLogin(userLoginDTO);
        Map<String,Object> claims=new HashMap<>();
        claims.put(JwtClaimsConstant.USER_ID,"test123");//user.getUserId()
        String token= JwtUtil.createJWT(jwtProperties.getUserSecretKey(), jwtProperties.getUserTtl(),claims);
        log.info(token);
        UserLoginVO userLoginVO=UserLoginVO.builder()
                .id(123L)//user.getUserId()
                //.openid(user.getOpenid())
                .token(token)
                .build();

        return Result.success(userLoginVO);
    }
}
